var kcgd = {
    alwayShowDetail: function (rowData) {
        $('#layout_kcgd').layout('remove', 'center');
        $('#layout_kcgd').layout('add', {
            region: 'center',
            split: true,
            href: $.webPath() + '/kcgl/kcgd/kcgd_detail?khId=' + rowData.id
        });
    },
    showDetail: function (rowData) {
        if (rowData && $("#kcgd_detail_id").val() != rowData.id) {
            kcgd.alwayShowDetail(rowData);
        }
    }
}

$(function () {
    $("#sbgs").gsjgqczcombobox();
    $("#cggs").gsjgtree(1);
    //表格初始加载
    $('#grid_kcgd').datagrid({
        url: $.webPath() + "/kcgl/kcgd/kcgdList",
        toolbar: "#toolbar_kcgd",
        fitColumns: false,
        singleSelect: true,
        pagination: true,
        pageNumber: 1,
        fit: true,
        checked: true,
        checkOnSelect: true,
        selectOnCheck: false,
        striped: true,
        showFooter: true,
        frozenColumns: [
            [
                {field: 'checked', title: '选择', align: 'center', checkbox: true},
                {field: 'resource_serial_number', align: 'center', width: 120, title: '挂单资源唯一号'},
                {field: 'matNo', align: 'center', width: 100, title: '材料号'},
                {field: 'packageId', align: 'center', width: 100, title: '包号'},
                {field: 'pc', align: 'center', width: 100, title: '产品码'},
                {field: 'apn', align: 'center', width: 100, title: '用途'},
                {field: 'productionDate', align: 'center', width: 80, title: '生产日期'},
                {field: 'layerDefect', align: 'center', width: 100, title: '表面缺陷'},
                {field: 'dateCreated_time', align: 'center', title: '创建日期', width: 80}
            ]
        ],
        columns: [
            [
                {field: 'prodDesc', title: '品名', width: 100, align: 'center'},
                {field: 'material', align: 'center', width: 100, title: '材质'},
                {field: 'spec', align: 'center', width: 100, title: '规格'},
                {field: 'brand', align: 'center', width: 100, title: '产地'},
                {field: 'warehouse', align: 'center', width: 100, title: '仓库'},
                {field: 'cate', align: 'center', width: 100, title: '产品分类' },
                {field: 'standard', align: 'center', width: 100, title: '钢材标准' },
                {field: 'measureCount', align: 'center', width: 80, title: '件数'},
                {field: 'measure', align: 'center', width: 80, title: '重量'},
                {field: 'price', align: 'center', title: '合同单价', width: 80,
                    formatter: function (value) {
                        var val = formatJeForHtml2(value);
                        return val;
                    }
                },
                {field: 'zyzt', align: 'center', title: '状态', width: 80,
                    formatter: function (value) {
                        if (value == "0")
                            return "已保存";
                        if (value == "1")
                            return "已挂单";
                        if (value == "2")
                            return "已撤销";
                        if (value == "3")
                            return "已销售";
                    }
                }
            ]
        ]
    });

    //**********按钮触发事件**********
    //挂单
    $("#kcgd_gd").click(function () {
        kcgd_gd('挂单', 'kcgd_gd');
    });


    //查询按钮
    $("#btn_kcgd_search").click(function () {
        kcgd_search();
    });

    //加载仓库
    $('#_ckmc').combobox({
        url: $.webPath() + '/organ/ck/sskcCkmcForSskc',
        valueField: 'id',
        textField: 'mc',
        panelHeight: '200',
        editable: true
    });

});

//挂单
function kcgd_gd(title, action) {
    var dataChecked = $("#grid_kcgd").datagrid("getChecked");
    if (dataChecked.length > 0) {
        var khIds = "";
        $.each(dataChecked, function (i, val) {
            khIds += (val['id'] + ',');
        });
        var href = $.webPath() + "/kcgl/kcgd/kcgd_gdcontent?khIds=" + khIds;
        var actionUrl = $.webPath() + "/kcgl/kcgd/kcgd_gd";
        kcgd_gdShowDialog(title, href, actionUrl);
    } else {
        $.messager.alert("提示", "请选择要挂单的卡号！", "warning");
    }

}

//库存挂单查询
function kcgd_search() {
    var gdwyh = $('#kcgd_gdwyh').val();
    var clh = $('#kcgd_clh').val();
    var bh = $('#kcgd_bh').val();
    var cpm = $('#kcgd_cpm').val();
    var pm = $('#kcgd_pm').val();
    var cz = $('#kcgd_cz').val();
    var ggxh = $('#kcgd_ggxh').val();
    var zyzt = $("#toolbar_kcgd input[name='kcgd_zyzt']").val();
    var kcgdstart = $('#kcgd_start').datebox('getValue');
    var kcgdend = $('#kcgd_end').datebox('getValue');
    $('#grid_kcgd').datagrid('load',
        {
            gdwyh: gdwyh,
            clh: clh,
            bh: bh,
            cpm: cpm,
            pm: pm,
            cz: cz,
            ggxh: ggxh,
            zyzt: zyzt,
            kcgdstart: kcgdstart,
            kcgdend: kcgdend
        }
    );
}


